<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <input type="text" v-model="formData.name" />
            <input type="text" v-model="info" />
            <input type="radio" value="1" v-model="formData.sex" checked />男
            <input type="radio" value="2" v-model="formData.sex" />女 {{formData.name}}
        </div>
        <script src="../vue.js"></script>
        <script>
            let vm = new Vue({
                el: '#app',
                data() {
                    return {
                        info: '',
                        name: '',
                        formData: {
                            name: '',
                            sex: 1,
                        },
                    };
                },
                methods: {
                    handle1() {
                        console.log(111);
                    },
                },
                watch: {
                    info(newVal, oldVal) {
                        console.log(newVal);
                        console.log(oldVal);
                    },
                    // 'formData.name'(newVal, oldVal) {
                    //     console.log(newVal);
                    //     console.log(oldVal);
                    // },
                    // formData(newVal, oldVal) {
                    //     console.log(neewVal);
                    //     console.log(oldVal);
                    //     deep: true;
                    // },
                    formData: {
                        handler(newVal, oldVal) {
                            for (const key in newVal) {
                                if (!newVal[key]) {
                                    console.log(key + '值没有!');
                                }
                            }
                            console.log(newVal);
                            console.log(oldVal);
                        },
                        deep: true, // 深度监听(对象和数组)
                        immediate: true, // 立即执行
                    },
                },
            });
        </script>
    </body>
</html>
